home *** CD-ROM | disk | FTP | other *** search
/ Plug-In Power Pack for Netscape Communicator / Plug-In Power Pack for Netscape Communicator.iso / plugins / dataviews / dvtools / demos / mfgdemo / mfg_model.c < prev    next >
C/C++ Source or Header  |  1997-07-10  |  11KB  |  335 lines

  1. #ifndef lint
  2. static char SccsId[]= "@(#)mfg_model.c    V1.10    3/15/95";
  3. #endif
  4.  
  5. /*------------------------------------------------------------------
  6. | file name -- mfg_model.c
  7. |
  8. |     Manufacturing model based on the internal cpu clock - update
  9. |    the machine functions.
  10. |
  11. |-----------------------------------------------------------------*/
  12.  
  13. #include "std.h"
  14. #include "dvstd.h"
  15. #include "dvtools.h"
  16. #include "Tfundecl.h"
  17. #include "mfg_vars.h"
  18. #include "mfg_data.h"
  19. #include "mfg_fundecl.h"
  20.  
  21.  
  22. LOCAL INT
  23.   temp_factor[NUM_STAMPERS] =
  24. {5, 9, 7}, cycle_timer, current_cycle_time, elapsed_time = 0, current_time = 0, current_cycle_counter;  /* (INT)welding_cycle[i] */
  25.  
  26. LOCAL FLOAT
  27.   oven_delta[NUM_OVENS], oven_counter[NUM_OVENS];
  28.  
  29. /*  welding message strings  */
  30. LOCAL CHAR
  31. * idle_msg = "IDLE", *welding_msg = "WELDING", *off_msg = "SHUTDOWN", *pos_msg = "POSITIONING", *complete_msg = "WELDING COMPLETE", *place_msg = "IN PLACE", *none_msg = "NONE", *move1_msg = "MOVE TO CELL 2", *move2_msg = "MOVE TO ACCUMULATOR", *load1_msg = "LOAD FROM STAMPING", *load2_msg = "LOAD FROM CELL 1", *online_msg = "ON-LINE";
  32.  
  33. /* stamping message strings  */
  34. LOCAL CHAR
  35. * off_man_msg = "OFF - MANUAL", *off_auto_msg = " OFF - AUTO ", *on_man_msg = " ON - MANUAL", *on_auto_msg = " ON - AUTO ";
  36.  
  37. void UpdateModel 
  38. V_P_ ((void))
  39. {
  40.   INT i;
  41.  
  42.   /* -------------------------------------------------------------------- */
  43.   /* Update the STAMPING AREA */
  44.   /* -------------------------------------------------------------------- */
  45.  
  46.   /* Update Stamping Pressure */
  47.   for (i = 0; i < NUM_STAMPERS; i++)
  48.     {
  49.       if (!stamping_on[i])
  50.         stamping_pressure[i] = 5;
  51.       else if (stamping_up[i])
  52.         stamping_pressure[i] = 35;
  53.       else
  54.         stamping_pressure[i] = 65;
  55.     }
  56.  
  57.   /*  Update Stamping Positions and Graphs */
  58.   elapsed_time = TIME - current_time;
  59.   if (elapsed_time >= STAMPING_UPDATE_TIME)
  60.     {
  61.       for (i = 0; i < NUM_STAMPERS; i++)
  62.         {
  63.           if (ActiveDrawport == DrawportId[STAMPING_VIEW] ||
  64.               ActiveDrawport == DrawportId[STAMPING_VIEW + 1 + i])
  65.             {
  66.               if (stamping_on[i] && stamping_auto[i])
  67.                 {
  68.                   stamping_up[i] = DOWN;
  69.                   (VOID) TdpDrawNext (ActiveDrawport);
  70.                   stamping_up[i] = UP;
  71.                   (VOID) TdpDrawNext (ActiveDrawport);
  72.  
  73.                   if (stamping_temp[i] < UPPER_TEMP)
  74.                     stamping_temp[i] += temp_factor[i];
  75.                 }
  76.               else if (stamping_temp[i] > LOWER_TEMP)
  77.                 stamping_temp[i] -= temp_factor[i];
  78.             }
  79.         }
  80.  
  81.       /* update the counters  based on the update timer  */
  82.       if ((welding_on[0] || welding_on[1]) && accum_pcs < 20)
  83.         ++accum_pcs;
  84.       else if (!welding_on[0] && !welding_on[1] && accum_pcs > 0)
  85.         --accum_pcs;
  86.  
  87.       total_pcs = accum_pcs + welding_on[0] + welding_on[1] + 3;
  88.       for (i = 0; i < NUM_STAMPERS; i++)
  89.         total_pcs = stamping_on[i];
  90.  
  91.       current_time = TIME;
  92.     }
  93.  
  94.   for (i = 0; i < NUM_STAMPERS; i++)
  95.     {
  96.       if (!stamping_on[i] && !stamping_auto[i])
  97.         (VOID) S_STRCPY (&stamping_status[i][0], off_man_msg);
  98.       else if (!stamping_on[i] && stamping_auto[i])
  99.         (VOID) S_STRCPY (&stamping_status[i][0], off_auto_msg);
  100.       else if (stamping_on[i] && !stamping_auto[i])
  101.         (VOID) S_STRCPY (&stamping_status[i][0], on_man_msg);
  102.       else if (stamping_on[i] && stamping_auto[i])
  103.         (VOID) S_STRCPY (&stamping_status[i][0], on_auto_msg);
  104.     }
  105.  
  106.  
  107.   /* -------------------------------------------------------------------- */
  108.   /* Update the WELDING AREA */
  109.   /* -------------------------------------------------------------------- */
  110.  
  111.   cycle_timer = TIME - current_cycle_time;
  112.   if (cycle_timer >= CYCLE_LENGTH)
  113.     {
  114.       for (i = 0; i < NUM_WELDERS; i++)
  115.         {
  116.           current_cycle_counter = (INT) welding_cycle[i];
  117.           if (ActiveDrawport == DrawportId[WELDING1_VIEW + i])
  118.             if (welding_on[i])
  119.               {
  120.                 /* Update the cycle counter */
  121.                 current_cycle_counter++;
  122.                 if (current_cycle_counter > NUM_OF_STEPS)
  123.                   current_cycle_counter = 1;
  124.  
  125.                 /* Update the welding status strings */
  126.                 if (current_cycle_counter == WELDING_STEP)
  127.                   (VOID) S_STRCPY (&welding_status[i][0], welding_msg);
  128.                 else
  129.                   (VOID) S_STRCPY (&welding_status[i][0], idle_msg);
  130.  
  131.  
  132.                 /* Update the welding piece status */
  133.                 switch (current_cycle_counter)
  134.                   {
  135.                   case 1:
  136.                     welding_unit_id[i]++;
  137.                     if (i == 0)
  138.                       (VOID) S_STRCPY (&welding_pcs_status[i][0], load1_msg);
  139.                     else
  140.                       (VOID) S_STRCPY (&welding_pcs_status[i][0], load2_msg);
  141.                     break;
  142.                   case 2:
  143.                     (VOID) S_STRCPY (&welding_pcs_status[i][0], pos_msg);
  144.                     break;
  145.                   case 3:
  146.                     (VOID) S_STRCPY (&welding_pcs_status[i][0], place_msg);
  147.                     break;
  148.                   case 4:
  149.                     break;
  150.                   case 5:
  151.                     (VOID) S_STRCPY (&welding_pcs_status[i][0], complete_msg);
  152.                     break;
  153.                   case 6:
  154.                     if (i == 0)
  155.                       (VOID) S_STRCPY (&welding_pcs_status[i][0], move1_msg);
  156.                     else
  157.                       (VOID) S_STRCPY (&welding_pcs_status[i][0], move2_msg);
  158.                     break;
  159.                   }             /*  end of switch statement  */
  160.  
  161.                 /* Update the Welding Temp */
  162.                 if (welding_temp[i] < WELD_TEMP_MAX)
  163.                   welding_temp[i] += 3;
  164.               }
  165.             else
  166.               {                 /*  Welder isn't on, reset   */
  167.                 (VOID) S_STRCPY (&welding_status[i][0], off_msg);
  168.                 (VOID) S_STRCPY (&welding_pcs_status[i][0], none_msg);
  169.                 current_cycle_counter = 0;
  170.                 if (welding_temp[i] > WELD_TEMP_MIN)
  171.                   welding_temp[i] -= 3;
  172.               }
  173.           welding_cycle[i] = (FLOAT) current_cycle_counter;
  174.         }
  175.       current_cycle_time = TIME;
  176.     }                           /*  end of cycle timer update  */
  177.  
  178.   /*  update the indicator lights on the welding screens */
  179.   for (i = 0; i < NUM_WELDERS; i++)
  180.     {
  181.       current_cycle_counter = (INT) welding_cycle[i];
  182.       if (welding_on[i])
  183.         (VOID) S_STRCPY (&welding_status[i][0], online_msg);
  184.       else
  185.         (VOID) S_STRCPY (&welding_status[i][0], off_msg);
  186.  
  187.       if (welding_on[i] && current_cycle_counter == WELDING_STEP)
  188.         {
  189.           welding_curr[i] = 275;
  190.           welding_green_on[i] = ON;
  191.           welding_yellow_on[i] = OFF;
  192.           welding_red_on[i] = OFF;
  193.         }
  194.       else if (welding_on[i] && current_cycle_counter != WELDING_STEP)
  195.         {
  196.           welding_curr[i] = 50;
  197.           welding_green_on[i] = OFF;
  198.           welding_yellow_on[i] = ON;
  199.           welding_red_on[i] = OFF;
  200.         }
  201.       else if (!welding_on[i])
  202.         {
  203.           welding_curr[i] = 0;
  204.           welding_green_on[i] = OFF;
  205.           welding_yellow_on[i] = OFF;
  206.           welding_red_on[i] = ON;
  207.         }
  208.     }
  209.  
  210.   /* -------------------------------------------------------------------- */
  211.   /* Update the PAINT SHOP AREA */
  212.   /* -------------------------------------------------------------------- */
  213.  
  214.   if (ActiveDrawport == DrawportId[PAINT_SHOP_VIEW])
  215.     {
  216.       for (i = 0; i < NUM_OVENS; i++)
  217.         {
  218.  
  219.           /* determine oven temperature */
  220.           if (oven_auto[i])
  221.             {
  222.               oven_delta[i] = (oven_set[i] - oven_temp[i]) / OVEN_FACTOR;
  223.               if (oven_temp[i] < MAX_OVEN_TEMP && oven_temp[i] > 0)
  224.                 oven_temp[i] = (oven_temp[i] + oven_delta[i]);
  225.               if (DV_VIABS (oven_set[i] - oven_temp[i]) < 1)
  226.                 oven_temp[i] = oven_set[i];
  227.             }
  228.  
  229.           /* check oven temperature alarms */
  230.           if (oven_temp[i] != oven_prev_temp[i])
  231.             {
  232.               /* we've changed alarm status, reset the acknowledge flag */
  233.               if ((oven_prev_temp[i] <= CAUTION_OVEN_TEMP &&
  234.                    oven_temp[i] > CAUTION_OVEN_TEMP) ||
  235.                   (oven_prev_temp[i] > CAUTION_OVEN_TEMP &&
  236.                    oven_temp[i] <= CAUTION_OVEN_TEMP) ||
  237.                   (oven_prev_temp[i] <= ALARM_OVEN_TEMP &&
  238.                    oven_temp[i] > ALARM_OVEN_TEMP) ||
  239.                   (oven_prev_temp[i] > ALARM_OVEN_TEMP &&
  240.                    oven_temp[i] <= ALARM_OVEN_TEMP))
  241.                 oven_ack[i] = 0;
  242.               oven_prev_temp[i] = oven_temp[i];
  243.             }
  244.  
  245.           /* Update the blinking */
  246.           if (oven_ack[i])
  247.             oven_blink[i] = 1;
  248.           else
  249.             {
  250.               oven_counter[i]++;
  251.               if (oven_counter[i] >= OVEN_BLINK_RATE)
  252.                 {
  253.                   oven_counter[i] = 0;
  254.                   oven_blink[i] = (oven_blink[i]) ? (FLOAT)0 : (FLOAT)1;
  255.                 }
  256.             }
  257.  
  258.         }
  259.     }
  260.  
  261.  
  262. }                               /* END UPDATE MODEL FUNCTION */
  263.  
  264. /* -------------------------------------------------------------------
  265. |
  266. | RaiseOrLowerStamper
  267. |    Function to control stampers when they are in manual mode.
  268. */
  269. void 
  270. RaiseOrLowerStamper (position, machine_id)
  271.      int position;
  272.      int machine_id;
  273. {
  274.   INT machine_index;
  275.  
  276.   machine_index = machine_id - 1;
  277.   if (!stamping_auto[machine_index])
  278.     {
  279.       if (position == LOWER_STAMPER_COMMAND)
  280.         stamping_up[machine_index] = DOWN;
  281.       else
  282.         stamping_up[machine_index] = UP;
  283.     }
  284. }
  285.  
  286. /* -------------------------------------------------------------------
  287. |
  288. | IncOrDecOven
  289. |    Function to control ovens when the are in manual mode.
  290. */
  291. void 
  292. IncOrDecOven (direction, oven_id)
  293.      int direction;
  294.      int oven_id;
  295. {
  296.   INT oven_index;
  297.  
  298.   oven_index = oven_id - 1;
  299.   if (!oven_auto[oven_index])
  300.     {
  301.       if (direction == INC_OVEN_COMMAND)
  302.         {
  303.           oven_output[oven_index] += 5;
  304.           if (oven_output[oven_index] > 100)
  305.             oven_output[oven_index] = 100;
  306.         }
  307.       else
  308.         {
  309.           oven_output[oven_index] -= 5;
  310.           if (oven_output[oven_index] < 0)
  311.             oven_output[oven_index] = 0;
  312.         }
  313.  
  314.       /* Set the oven temperature */
  315.       oven_temp[oven_index] = oven_output[oven_index] * 6;
  316.     }
  317. }
  318.  
  319. /* -------------------------------------------------------------------
  320. |
  321. | AckOvenAlarm
  322. |    Function to acknowledg oven temperature alarms.
  323. */
  324. void 
  325. AckOvenAlarm (oven_id)
  326.      int oven_id;
  327. {
  328.   INT oven_index;
  329.  
  330.   /* Only acknoledge the alarm if an alarm is occuring */
  331.   oven_index = oven_id - 1;
  332.   if (oven_temp[oven_index] > CAUTION_OVEN_TEMP)
  333.     oven_ack[oven_index] = 1;
  334. }
  335.